package jmu.edu.yjc.controller;

import io.swagger.annotations.ApiOperation;
import jmu.edu.yjc.annotation.SystemLog;
import jmu.edu.yjc.domain.ResponseResult;
import jmu.edu.yjc.domain.dto.UserRegisterDto;
import jmu.edu.yjc.domain.entity.User;
import jmu.edu.yjc.interfaces.AddGroup;
import jmu.edu.yjc.interfaces.UpdateGroup;
import jmu.edu.yjc.service.user.UserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;
    @GetMapping("/userInfo")
    @ApiOperation(value = "获取用户信息")
    public ResponseResult userInfo(){
        return userService.userInfo();
    }
    @PutMapping("/userInfo")
    @SystemLog(businessName = "更新用户信息")
    @ApiOperation(value = "更新用户信息")
    public ResponseResult savaUserInfo(@RequestBody @Validated(UpdateGroup.class) User user){
        return userService.saveUserInfo(user);
    }
    @PostMapping("/register")
    @ApiOperation(value = "注册用户")
    public ResponseResult userRegister(HttpServletRequest request, @RequestBody @Validated(AddGroup.class)UserRegisterDto user){
        return userService.userRegister(request, user);
    }
    @PostMapping("/updatePassword")
    public ResponseResult updatePassword(HttpServletRequest request, @RequestBody @Validated(UpdateGroup.class) UserRegisterDto user) {
        return userService.updatePassword(request, user);
    }
}
